package com.woniuxy.ams.controller;

import com.woniuxy.ams.entity.Project;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dayAssessProject")
public class ProjectController {
    ProjectService projectService;
    @Autowired(required = false)
    public void setProjectService(ProjectService projectService) {
        this.projectService = projectService;
    }

    @RequestMapping("/insert")
    public ResultEntity<Integer> insertProject(Project project){
        int code = projectService.insert(project);
        if (code!=0){
            return new ResultEntity<>(200,"新增日考核项成功！",code);
        }else{
            return new ResultEntity<>(400,"新增日考核项失败！",code);
        }

    }
    @RequestMapping("/delete")
    public ResultEntity<Integer> deleteProject(int id){
        int code = projectService.delete(id);
        if (code!=0){
            return new ResultEntity<>(200,"删除日考核项成功！",code);
        }else{
            return new ResultEntity<>(400,"删除日考核项失败！",code);
        }
    }
    @RequestMapping("/update")
    public ResultEntity<Integer> updateProject(Project project){
        int code = projectService.update(project);
        if (code!=0){
            return new ResultEntity<>(200,"修改日考核项成功！",code);
        }else{
            return new ResultEntity<>(400,"修改日考核项失败！",code);
        }
    }

    @RequestMapping("/findAllProject")
    public ResultEntity<List<Project>> findAllProject(){
        List<Project> all = projectService.findAll();
        if (all!=null){
            return new ResultEntity<>(200,"查询成功！",all);
        }else {
            return new ResultEntity<>(400,"数据库为空或出现错误",null);
        }
    }

    @RequestMapping("/findProject")
    public ResultEntity<List<Project>> findProject(@RequestParam("idStr") String idStr){
        List<Project> all = projectService.findProjectById(idStr);
        if (all!=null){
            return new ResultEntity<>(200,"查询成功！",all);
        }else {
            return new ResultEntity<>(400,"数据库为空或出现错误",null);
        }
    }



}
